-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[RISCV] Use LiveIntervals to determine if AVL dominates when coalescing #118285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] Use LiveIntervals to determine if AVL dominates when coalescing #118285
Conversation
In order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli. Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move. We can instead use live intervals to check that the reaching definition is the same at both instructions. On its own this doesn't have much of an impact, but helps a lot in llvm#118283 and enables coalescing in about 60 of the test cases from that PR.
Your org has enabled the Graphite merge queue for merging into mainAdd the label “FP Bundles” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
|
@llvm/pr-subscribers-backend-risc-v Author: Luke Lau (lukel97) ChangesIn order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli. Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move. We can instead use live intervals to check that the reaching definition is the same at both instructions. On its own this doesn't have much of an impact, but helps a lot in #118283 and enables coalescing in about 60 of the test cases from that PR. Full diff: https://github.com/llvm/llvm-project/pull/118285.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 052b4a61298223..93f9bf5ceba138 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -1619,14 +1619,15 @@ bool RISCVInsertVSETVLI::canMutatePriorConfig(
}
auto &AVL = MI.getOperand(1);
- auto &PrevAVL = PrevMI.getOperand(1);
- // If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
- // For now just check that PrevMI uses the same virtual register.
- if (AVL.isReg() && AVL.getReg() != RISCV::X0 &&
- (!MRI->hasOneDef(AVL.getReg()) || !PrevAVL.isReg() ||
- PrevAVL.getReg() != AVL.getReg()))
- return false;
+ // If the AVL is a register, we need to make sure its definition is the same
+ // at PrevMI as it was at MI.
+ if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
+ VNInfo *VNI = getVNInfoFromReg(AVL.getReg(), MI, LIS);
+ VNInfo *PrevVNI = getVNInfoFromReg(AVL.getReg(), PrevMI, LIS);
+ if (!VNI || !PrevVNI || VNI->id != PrevVNI->id)
+ return false;
+ }
}
assert(PrevMI.getOperand(2).isImm() && MI.getOperand(2).isImm());
diff --git a/llvm/test/CodeGen/RISCV/rvv/compressstore.ll b/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
index bfb2d0a3accc44..a407cd048ffe3f 100644
--- a/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
@@ -652,15 +652,14 @@ define void @test_compresstore_v64i32(ptr %p, <64 x i1> %mask, <64 x i32> %data)
; RV64-NEXT: vse32.v v24, (a0)
; RV64-NEXT: vsetivli zero, 4, e8, mf2, ta, ma
; RV64-NEXT: vslidedown.vi v8, v0, 4
-; RV64-NEXT: vsetvli zero, zero, e32, m2, ta, ma
-; RV64-NEXT: vmv.x.s a2, v0
; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
+; RV64-NEXT: vmv.x.s a1, v0
; RV64-NEXT: vcompress.vm v24, v16, v8
-; RV64-NEXT: vcpop.m a1, v8
-; RV64-NEXT: cpopw a2, a2
-; RV64-NEXT: slli a2, a2, 2
-; RV64-NEXT: add a0, a0, a2
-; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
+; RV64-NEXT: vcpop.m a2, v8
+; RV64-NEXT: cpopw a1, a1
+; RV64-NEXT: slli a1, a1, 2
+; RV64-NEXT: add a0, a0, a1
+; RV64-NEXT: vsetvli zero, a2, e32, m8, ta, ma
; RV64-NEXT: vse32.v v24, (a0)
; RV64-NEXT: ret
;
|
…lsewhere in RISCVInsertVSETVLI and in LiveIntervals.cpp
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
preames
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/9451 Here is the relevant piece of the build log for the reference |
In order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli.
Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move to post-RA. We can instead use live intervals to check that the reaching definition is the same at both instructions.
On its own this doesn't have much of an impact, but helps a lot in #118283 and enables coalescing in about 60 of the test cases from that PR.